home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg4.cab / test_netrc.py < prev    next >
Text File  |  2005-11-19  |  1KB  |  49 lines

  1.  
  2. import netrc, os, unittest, sys
  3. from test import test_support
  4.  
  5. TEST_NETRC = """
  6. machine foo login log1 password pass1 account acct1
  7.  
  8. macdef macro1
  9. line1
  10. line2
  11.  
  12. macdef macro2
  13. line3
  14. line4
  15.  
  16. default login log2 password pass2
  17.  
  18. """
  19.  
  20. temp_filename = test_support.TESTFN
  21.  
  22. class NetrcTestCase(unittest.TestCase):
  23.  
  24.     def setUp (self):
  25.         mode = 'w'
  26.         if sys.platform not in ['cygwin']:
  27.             mode += 't'
  28.         fp = open(temp_filename, mode)
  29.         fp.write(TEST_NETRC)
  30.         fp.close()
  31.         self.netrc = netrc.netrc(temp_filename)
  32.  
  33.     def tearDown (self):
  34.         del self.netrc
  35.         os.unlink(temp_filename)
  36.  
  37.     def test_case_1(self):
  38.         self.assert_(self.netrc.macros == {'macro1':['line1\n', 'line2\n'],
  39.                                            'macro2':['line3\n', 'line4\n']}
  40.                                            )
  41.         self.assert_(self.netrc.hosts['foo'] == ('log1', 'acct1', 'pass1'))
  42.         self.assert_(self.netrc.hosts['default'] == ('log2', None, 'pass2'))
  43.  
  44. def test_main():
  45.     test_support.run_unittest(NetrcTestCase)
  46.  
  47. if __name__ == "__main__":
  48.     test_main()
  49.